package com.eztalks.paypal;

import org.junit.Test;

import com.paypal.api.payments.CreditCard;
import com.paypal.base.Constants;
import com.paypal.base.rest.APIContext;

public class Card {
	private static final String clientID = "AfcY59o_imV3VlN4VYpqH30gIfrhZ5WrY4GMyfZFvL94EXG_BQttwRrlkbgrfye6H3zgqFEV3e2brjUy";
	private static final String clientSecret = "EFX2Loz2VE-hdidZ5ktob8Aq4FqJJYFctFJKrhkKbPkLAnnjlkueix4-7MoHfz2V3KhPVTDJSyFMgzSC";

	@Test
	public void createCard() {
		// ###CreditCard
		// A resource representing a credit card that can be
		// used to fund a payment.
		CreditCard creditCard = new CreditCard();
		creditCard.setExpireMonth(11);
		creditCard.setExpireYear(2018);
		creditCard.setNumber("4669424246660779");
		creditCard.setCvv2(0123);
		creditCard.setType("visa");
		// creditCard.setExternalCustomerId(externalCustomerId)

		try {

			// ### Api Context
			// Pass in a `ApiContext` object to authenticate
			// the call and to send a unique request id
			// (that ensures idempotency). The SDK generates
			// a request id if you do not pass one explicitly.
			APIContext apiContext = new APIContext(clientID, clientSecret, Constants.SANDBOX);

			// ###Save
			// Creates the credit card as a resource
			// in the PayPal vault. The response contains
			// an 'id' that you can use to refer to it
			// in the future payments.
			CreditCard createdCreditCard = creditCard.create(apiContext);
			System.out.println(creditCard);
			System.out.println(createdCreditCard);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
